import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

// /* Router Modules */
// import componentsRouter from "./modules/components";
// import chartsRouter from "./modules/charts";
// import tableRouter from "./modules/table";
// import nestedRouter from "./modules/nested";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'WMS',
        meta: { title: 'WMS', icon: 'logo', affix: true }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/depotManage',
    component: Layout,
    alwaysShow: true,
    name: 'DepotManage',
    meta: {
      title: 'depotManagement',
      icon: 'depot'
    },
    children: [
      {
        path: '/depot',
        component: () => import('@/views/business/depotManage/depot/index.vue'),
        name: 'Depot',
        meta: { title: 'depotManagement' }
      },
      {
        path: '/partition',
        component: () =>
          import('@/views/business/depotManage/partition/index.vue'),
        name: 'Partition',
        meta: { title: 'partitionManagement' }
      },
      {
        path: '/locationType',
        component: () =>
          import('@/views/business/depotManage/locationType/index.vue'),
        name: 'LocationType',
        meta: { title: 'locationType' }
      },
      {
        path: '/location',
        component: () =>
          import('@/views/business/depotManage/location/index.vue'),
        name: 'Location',
        meta: { title: 'locationManagement' }
      },
      {
        path: '/containerType',
        component: () =>
          import('@/views/business/depotManage/containerType/index.vue'),
        name: 'FlowBoxType',
        meta: { title: 'containerType' },
        hidden: true
      },
      {
        path: '/container',
        component: () =>
          import('@/views/business/depotManage/container/index.vue'),
        name: 'FlowBox',
        meta: { title: 'containerManagement' },
        hidden: true
      }
    ]
  },
  {
    path: '/inventoryManage',
    component: Layout,
    alwaysShow: true,
    name: 'InventoryManage',
    meta: {
      title: 'inventoryManagement',
      icon: 'inventory'
    },
    children: [
      {
        path: '/inventory',
        component: () =>
          import('@/views/business/inventoryManage/inventory/index.vue'),
        name: 'Inventory',
        meta: { title: 'inventoryManagement' }
      },
      {
        path: '/batchInventory',
        component: () =>
          import('@/views/business/inventoryManage/batchInventory/index.vue'),
        name: 'BatchInventory',
        meta: { title: 'batchInventory' }
      }
    ]
  },
  {
    path: '/packagingMaterials',
    component: Layout,
    alwaysShow: true,
    name: 'PackagingMaterials',
    meta: { title: 'packagingMaterialManagement', icon: 'material' },
    children: [
      {
        path: '/material',
        name: 'Material',
        component: () =>
          import('@/views/business/packagingMaterials/material/index.vue'),
        meta: { title: 'packagingMaterialManagement' }
      }
    ]
  },
  {
    path: '/productManage',
    component: Layout,
    alwaysShow: true,
    name: 'ProductManage',
    meta: {
      title: 'productManagement',
      icon: 'product'
    },
    children: [
      {
        path: '/product',
        component: () =>
          import('@/views/business/productManage/product/index.vue'),
        name: 'Product',
        meta: { title: 'productManagement' }
      }
    ]
  },
  {
    path: '/warehouseManage',
    component: Layout,
    alwaysShow: true,
    name: 'WarehouseManage',
    meta: {
      title: 'warehouseManagement',
      icon: 'warehouse'
    },
    children: [
      {
        path: '/warehousing',
        name: 'Warehousing',
        component: () =>
          import('@/views/business/warehouseManage/warehousing/index.vue'),
        meta: { title: 'warehousingOperation' },
        hidden: true
      },
      {
        path: '/inboundScan',
        name: 'InboundScan',
        component: () =>
          import('@/views/business/warehouseManage/inboundScan/index.vue'),
        meta: { title: 'inboundScan' }
      },
      {
        path: '/standardInbound/:orderNo',
        name: 'StandardInbound',
        component: () =>
          import('@/views/business/warehouseManage/standardInbound/index.vue'),
        meta: { title: 'standardInbound' },
        beforeEnter: (to, from, next) => {
          to.meta.suffix = to.params.orderNo;
          next();
        },
        hidden: true
      },
      {
        path: '/fastInbound/:orderNo',
        name: 'FastInbound',
        component: () =>
          import('@/views/business/warehouseManage/fastInbound/index.vue'),
        meta: { title: 'fastInbound' },
        beforeEnter: (to, from, next) => {
          to.meta.suffix = to.params.orderNo;
          next();
        },
        hidden: true
      },
      {
        path: '/skuInbound/:orderNo',
        name: 'SkuInbound',
        component: () =>
          import('@/views/business/warehouseManage/skuInbound/index.vue'),
        meta: { title: 'skuInbound' },
        beforeEnter: (to, from, next) => {
          to.meta.suffix = to.params.orderNo;
          next();
        },
        hidden: true
      },
      {
        path: '/shelveScan',
        name: 'ShelveScan',
        component: () =>
          import('@/views/business/warehouseManage/shelveScan/index.vue'),
        meta: { title: 'shelveScan' }
      },
      {
        path: '/skuShelve/:boxNo',
        name: 'SkuShelve',
        component: () =>
          import('@/views/business/warehouseManage/skuShelve/index.vue'),
        meta: { title: 'skuShelve' },
        beforeEnter: (to, from, next) => {
          to.meta.suffix = to.params.boxNo;
          next();
        },
        hidden: true
      },
      {
        path: '/skuPartShelve/:orderNo',
        name: 'SkuPartShelve',
        component: () =>
          import('@/views/business/warehouseManage/skuPartShelve/index.vue'),
        meta: { title: 'skuPartShelve' },
        beforeEnter: (to, from, next) => {
          to.meta.suffix = to.params.orderNo;
          next();
        },
        hidden: true
      },
      {
        path: '/boxShelve/:orderNo',
        name: 'BoxShelve',
        component: () =>
          import('@/views/business/warehouseManage/boxShelve/index.vue'),
        meta: { title: 'boxShelve' },
        beforeEnter: (to, from, next) => {
          to.meta.suffix = to.params.orderNo;
          next();
        },
        hidden: true
      },
      {
        path: '/harvest',
        component: () =>
          import('@/views/business/warehouseManage/harvest/index.vue'),
        name: 'Harvest',
        meta: { title: 'receivingManagement' }
      },
      {
        path: '/returnSplit',
        component: () =>
          import('@/views/business/warehouseManage/returnSplit/index.vue'),
        name: 'ReturnSplit',
        meta: { title: 'returnSplit' }
      },
      {
        path: '/returnNoSplit',
        component: () =>
          import('@/views/business/warehouseManage/returnNoSplit/index.vue'),
        name: 'ReturnNoSplit',
        meta: { title: 'returnNoSplit' }
      }
    ]
  },
  {
    path: '/outboundManage',
    component: Layout,
    alwaysShow: true,
    name: 'OutboundManage',
    meta: {
      title: 'outboundManagement',
      icon: 'exWarehouse'
    },
    children: [
      {
        path: '/invoicing',
        component: () =>
          import('@/views/business/outboundManage/invoicing/index.vue'),
        name: 'Invoicing',
        meta: { title: 'outboundPrint' },
        hidden: true
      },
      {
        path: '/scratchCode',
        component: () =>
          import('@/views/business/outboundManage/scratchCode/index.vue'),
        name: 'ScratchCode',
        meta: { title: 'captureCodeComparison' }
      },
      {
        path: '/merge',
        component: () =>
          import('@/views/business/outboundManage/merge/index.vue'),
        name: 'Merge',
        meta: { title: 'merge' }
      },
      {
        path: '/outboundOrder',
        component: () =>
          import('@/views/business/outboundManage/outboundOrder/index.vue'),
        name: 'OutboundOrder',
        meta: { title: 'outboundOrderManagement' }
      }
    ]
  },
  {
    path: '/pickManage',
    component: Layout,
    alwaysShow: true,
    name: 'PickManage',
    meta: {
      title: 'pickManage',
      icon: 'el-icon-box'
    },
    children: [
      {
        path: '/createPick',
        component: () =>
          import('@/views/business/pickManage/createPick/index.vue'),
        name: 'createPick',
        meta: { title: 'createPick' }
      },
      {
        path: '/pickOrder',
        component: () =>
          import('@/views/business/pickManage/pickOrder/index.vue'),
        name: 'pickOrder',
        meta: { title: 'pickOrder' }
      }
    ]
  },
  {
    path: '/operateManage',
    component: Layout,
    alwaysShow: true,
    name: 'OperateManage',
    meta: {
      title: 'operationManagement',
      icon: 'order'
    },
    children: [
      {
        path: '/back',
        component: () =>
          import('@/views/business/operateManage/back/index.vue'),
        name: 'Back',
        meta: { title: 'retirementManagement' }
      },
      {
        path: '/intercept',
        component: () =>
          import('@/views/business/operateManage/intercept/index.vue'),
        name: 'Intercept',
        meta: { title: 'interceptionManagement' }
      },
      {
        path: '/unownedGoods',
        component: () =>
          import('@/views/business/operateManage/unownedGoods/index.vue'),
        name: 'UnownedGoods',
        meta: { title: 'unownedGoodsManagement' }
      },
      {
        path: '/problemItem',
        component: () =>
          import('@/views/business/operateManage/problemItem/index.vue'),
        name: 'problemItem',
        meta: { title: 'problemItemManagement' }
      },
      {
        path: '/destruction',
        component: () =>
          import('@/views/business/operateManage/destruction/index.vue'),
        name: 'destruction',
        meta: { title: 'destructionManagement' }
      },
      {
        path: '/inventoryOrder',
        component: () =>
          import('@/views/business/operateManage/inventoryOrder/index.vue'),
        name: 'inventory',
        meta: { title: 'inventoryOrderManagement' }
      }
      // {
      //   path: '/print',
      //   component: () =>
      //     import('@/views/business/operateManage/print/index.vue'),
      //   name: 'Print',
      //   meta: { title: 'restartPrintManagement' }
      // }
    ]
  },
  {
    path: '/system',
    component: Layout,
    alwaysShow: true,
    name: 'System',
    meta: {
      title: 'systemSettings',
      icon: 'system'
    },
    children: [
      {
        path: '/category',
        component: () => import('@/views/system/category/index.vue'),
        name: 'Category',
        meta: { title: 'categoryManagement' }
      },
      {
        path: '/printerSetup',
        component: () => import('@/views/system/printerSetup/index.vue'),
        name: 'printerSetup',
        meta: { title: 'printerSetup' }
      }
    ]
  },
  // {
  //   path: '/WMS Order',
  //   component: Layout,
  //   alwaysShow: true,
  //   name: 'WMS Order',
  //   meta: {
  //     title: 'WMSOrder',
  //     icon: 'order'
  //   },
  //   children: [
  //     {
  //       path: '/WarehouseEntry',
  //       component: () =>
  //         import('@/views/system/WMS Order/warehouseEntry/index.vue'),
  //       name: 'WarehouseEntry',
  //       meta: { title: 'WarehouseReceiptManagement' }
  //     },
  //     {
  //       path: '/outboundOrder1',
  //       component: () =>
  //         import('@/views/system/WMS Order/outboundOrder/index.vue'),
  //       name: 'OutboundOrder1',
  //       meta: { title: 'outboundOrderManagement' }
  //     }
  //   ]
  // },
  // {
  //   path: 'OMS Inventory',
  //   component: Layout,
  //   alwaysShow: true,
  //   name: 'OMS Inventory',
  //   meta: {
  //     title: 'OMS库存管理',
  //     icon: 'order'
  //   },
  //   children: [
  //     {
  //       path: '/management',
  //       component: () => import('@/views/system/OMS Inventory/management'),
  //       name: 'Management',
  //       meta: { title: '库存管理' }
  //     },
  //     {
  //       path: '/reconciliation',
  //       component: () => import('@/views/system/OMS Inventory/reconciliation'),
  //       name: 'Reconciliation',
  //       meta: { title: '库存对账' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
